package com.hnucm.cooklife.custom;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.appbar.CollapsingToolbarLayout;

public class NestCollapsingToolbarLayout extends CollapsingToolbarLayout {

    private boolean mIsScrimsShown = false;
    private OnScrimsShowListener mScrimsShowListener;

    public NestCollapsingToolbarLayout(@NonNull Context context) {
        super(context);
    }

    public NestCollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public NestCollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setScrimsShown(boolean shown, boolean animate) {
        super.setScrimsShown(shown, animate);
        if(mIsScrimsShown != shown){
            mIsScrimsShown = shown;
            if(mScrimsShowListener != null){
                mScrimsShowListener.onScrimsShowChange(
                        this,mIsScrimsShown
                );
            }
        }
    }

    public void setScrimsShowListener(OnScrimsShowListener scrimsShowListener) {
        mScrimsShowListener = scrimsShowListener;
    }

    public interface OnScrimsShowListener{
        void onScrimsShowChange(
                NestCollapsingToolbarLayout nestCollapsingToolbarLayout,
                boolean isScrimsShow
        );
    }
}
